﻿//using System;
//using System.Collections.Generic;
//using UnityEngine;
//using VoxelBlock.VoxelBlock3D;
//using VoxelBlock;using Vector3Int = VoxelBlock.Vector3Int;


//public class OperationImplementSliceAddOrPaint : OperationImplement
//{

//    /// <summary>
//    /// 空白区域边界判断条件
//    /// </summary>
//    Func<Vector3Int, bool> FuncIsContinue;

//    /// <summary>
//    /// 获得空白区域边界判断条件
//    /// </summary>
//    Func<Func<Vector3Int, bool>> getFuncIsContinue;


//    int oldlayer = 0;

//    int startLayer = 0;
//    GameObject meshSliceCollider;
//    Transform mainCameraY;

//    Dictionary<Vector3Int, Voxel3D> mainAllData;

//    /// <summary>
//    /// 一样的颜色才可以
//    /// </summary>
//    int mSliceUVxy;
//    /// <summary>
//    /// 对一片进行操作时保存6个方向中的一个
//    /// </summary>
//    VoxelDirection sliceDirection;

//    Func<VoxelDirection> SetSliceDirection;

//    /// <summary>
//    /// 对一片进行操作时保存6个方向中的一个
//    /// </summary>
//    Vector3Int meshSliceXYZ = new Vector3Int();
//    Dictionary<Vector3Int, Vector3Int> mSlicesBlocks = new Dictionary<Vector3Int, Vector3Int>();

//    public OperationImplementSliceAddOrPaint( GameObject meshSliceCollider
//        , Transform mainCameraY, Func<VoxelDirection> setSliceDirection , Dictionary<Vector3Int, Voxel3D> mainAllData
//        , Func<Func<Vector3Int, bool>> getFuncIsContinue
//        )
//    {
//        this.meshSliceCollider = meshSliceCollider;
//        this.mainCameraY = mainCameraY;
//        this.SetSliceDirection = setSliceDirection;
//        this.mainAllData = mainAllData;
//        this.getFuncIsContinue = getFuncIsContinue;
//    }


//    bool isNull = false;

//    public override void Start(StartArg arg)
//    {
//        base.Start(arg);

//        FuncIsContinue = getFuncIsContinue();

//        sliceDirection = SetSliceDirection();
//        Vector3Int bPosition = arg.StartPosition;
//        Vector3Int meshSliceXYZ = new Vector3Int(0, 0, 0);

//        meshSliceCollider.gameObject.SetActive(true);
//        meshSliceCollider.transform.position = bPosition;// new Vector3();
//        switch (sliceDirection)
//        {
//            case VoxelDirection.Right:
//                meshSliceCollider.transform.eulerAngles = new Vector3(90, 0, 0);
//                meshSliceXYZ = new Vector3Int(1, 0, 0);
//                break;
//            case VoxelDirection.Left:
//                meshSliceCollider.transform.eulerAngles = new Vector3(90, 0, 0);
//                meshSliceXYZ = new Vector3Int(-1, 0, 0);
//                break;
//            case VoxelDirection.Up:
//                meshSliceCollider.transform.eulerAngles = new Vector3(0, mainCameraY.eulerAngles.y, 0);
//                meshSliceXYZ = new Vector3Int(0, 1, 0);
//                break;
//            case VoxelDirection.Down:
//                meshSliceCollider.transform.eulerAngles = new Vector3(0, mainCameraY.eulerAngles.y, 0);
//                meshSliceXYZ = new Vector3Int(0, -1, 0);
//                break;
//            case VoxelDirection.Front:
//                meshSliceCollider.transform.eulerAngles = new Vector3(90, 0, 0);
//                meshSliceXYZ = new Vector3Int(0, 0, 1);
//                break;
//            case VoxelDirection.Break:
//                meshSliceCollider.transform.eulerAngles = new Vector3(90, 0, 0);
//                meshSliceXYZ = new Vector3Int(0, 0, -1);
//                break;
//            default:
//                break;
//        }

//        mSlicesBlocks = new Dictionary<Vector3Int, Vector3Int>();
//        if (nowDrawVoxel3DCore.allVoxels.ContainsKey(bPosition))
//        {
//            mSliceUVxy = nowDrawVoxel3DCore.allVoxels[bPosition].uvKey;
//            BasicAlgorithm.GetSliceBlock(mSlicesBlocks, sliceDirection, bPosition, mSliceUVxy, nowDrawVoxel3DCore.allVoxels, mainAllData);
//            isNull = false;
//        }
//        else if (mainAllData.ContainsKey(bPosition - meshSliceXYZ))
//        {
//            mSliceUVxy = mainAllData[bPosition - meshSliceXYZ].uvKey;
//            BasicAlgorithm.GetSliceBlock(mSlicesBlocks, sliceDirection, bPosition, meshSliceXYZ, mSliceUVxy, nowDrawVoxel3DCore.allVoxels, mainAllData);
//            isNull = false;
//        }
//        else
//        {
//            bPosition = arg.StartPosition;
//            mSliceUVxy = arg.nowSelectUVKey;
//            BasicAlgorithm.GetSliceBlock(mSlicesBlocks, sliceDirection, bPosition, nowDrawVoxel3DCore.allVoxels, FuncIsContinue);
//            isNull = true;
//        }


//        switch (sliceDirection)
//        {
//            case VoxelDirection.Right:
//                meshSliceXYZ = new Vector3Int(1, 0, 0);
//                startLayer = (int)bPosition.x;
//                oldlayer = (int)bPosition.x - startLayer;
//                break;
//            case VoxelDirection.Left:
//                meshSliceXYZ = new Vector3Int(-1, 0, 0);
//                startLayer = (int)bPosition.x;
//                oldlayer = -(int)bPosition.x + startLayer;
//                break;
//            case VoxelDirection.Up:
//                meshSliceXYZ = new Vector3Int(0, 1, 0);
//                startLayer = (int)bPosition.y;
//                oldlayer = (int)bPosition.y - startLayer;
//                break;
//            case VoxelDirection.Down:
//                meshSliceXYZ = new Vector3Int(0, -1, 0);
//                startLayer = (int)bPosition.y;
//                oldlayer = -(int)bPosition.y + startLayer;
//                break;
//            case VoxelDirection.Front:
//                meshSliceXYZ = new Vector3Int(0, 0, 1);
//                startLayer = (int)bPosition.z;
//                oldlayer = (int)bPosition.z - startLayer;
//                break;
//            case VoxelDirection.Break:
//                meshSliceXYZ = new Vector3Int(0, 0, -1);
//                startLayer = (int)bPosition.z;
//                oldlayer = -(int)bPosition.z + startLayer;
//                break;
//        }
//        int index = 0;
//        if (isNull)
//        {
//            Voxel3D[] array = new Voxel3D[mSlicesBlocks.Count];
//            foreach (Vector3Int position in mSlicesBlocks.Values)
//            {
//                array[index] = new Voxel3D(position, arg.nowSelectUVKey);
//                index++;
//            }
//            var data = nowDrawVoxel3DCore.DrawAddBlock(array);
//            historyRecordBreakList.AddRange(data);
//        }
//        else
//        {
//            Vector3Int[] array = new Vector3Int[mSlicesBlocks.Count];
//            foreach (Vector3Int position in mSlicesBlocks.Values)
//            {
//                array[index] = position;
//                index++;
//            }
//            var data = nowDrawVoxel3DCore.DrawAddOrPaintBlock(array, arg.nowSelectUVKey);
//            historyRecordFrontList.AddRange(data.Item1);
//            historyRecordBreakList.AddRange(data.Item2);
//        }

//    }

//    public override void Run(RunArg arg)
//    {

//    }

//    public override void Over(OverArg arg)
//    {

//        meshSliceCollider.gameObject.SetActive(false);
//        if (isNull)
//        {
//            //historyRecordBreakList = new List<SimpleVoxel>(attemptDictionaryVoxels.Count);
//            //foreach (var item in attemptDictionaryVoxels.Values)
//            //{
//            //    historyRecordBreakList.Add(new SimpleVoxel(item.worldPosition, item.uvKey));
//            //}
//            if (historyRecordBreakList.Count > 0)
//            {
//                proxy.Write(VoxelCategories.Operation.Add, historyRecordFrontList, historyRecordBreakList);
//                historyRecordBreakList = new List<SimpleVoxel>();
//                historyRecordFrontList = new List<SimpleVoxel>();
//            }
//        }
//        else
//        {
//            if (historyRecordFrontList.Count > 0 || historyRecordBreakList.Count > 0)
//            {
//                proxy.Write(VoxelCategories.Operation.AddOrPaint, historyRecordFrontList, historyRecordBreakList);
//                historyRecordBreakList = new List<SimpleVoxel>();
//                historyRecordFrontList = new List<SimpleVoxel>();
//            }
//        }

//    }

//}


